package com.itheima.controller;


import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/checkItem")
@Api(tags = "检查项业务操作相关接口")
public class CheckItemController {

    @Reference
    CheckItemService checkItemService;


    @GetMapping("/queryPage")
    @ApiOperation("检查项分页查询数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage" ,value = "当前页码"),
            @ApiImplicitParam(name = "pageSize" ,value = "每页条数"),
    })
    public PageResult queryPage(Integer currentPage,Integer pageSize){

        PageResult pageResult = checkItemService.queryPage(currentPage, pageSize);

        return pageResult;

    }

    @GetMapping("/delete/{id}")
    @ApiOperation("删除检查项列表数据")
    @ApiImplicitParam("检查项id值")
    public Result delete(@PathVariable Integer id){

        Result result = checkItemService.delete(id);

        return result;
    }

    @PostMapping("/save")
    @ApiOperation("添加检查项")
    public Result save(@RequestBody CheckItem checkItem){

        return checkItemService.add(checkItem);

    }

    @PostMapping("/update")
    @ApiOperation("修改检查项数据")
    public Result update(@RequestBody CheckItem checkItem){

        return checkItemService.update(checkItem);
    }

    @GetMapping("/queryString/{queryString}")
    @ApiOperation("根据项目编码/项目名称查询检查项")
    public  PageResult queryString(@PathVariable String queryString){

        return checkItemService.queryString(queryString);
    }

    @GetMapping("/queryAll")
    public Result queryAll(){
        try{

            return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,checkItemService.queryAll());

        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_CHECKITEM_FAIL);
        }

    }


}
